﻿using LcAudit.BPM.Core.Dal;
using LcAudit.BPM.Core.Model;
using LcAudit.Common;
using LcAudit.Common.Data;
using LcAudit.Common.Data.Filter;
using LcAudit.Common.Provider;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace LcAudit.BPM.Core.Bll
{
    public class bagbidderBll
    {
        public static bagbidderBll Instance
        {
            get { return SingletonProvider<bagbidderBll>.Instance; }
        }

        public string Add(bagbidder u)
        {
            int uid = 0;
            string msg = "添加失败！";
            uid = bagbidderDal.Instance.Insert(u);
            if (uid > 0)
            {
                msg = "添加成功！";
            }

            return new JsonMessage { Data = uid.ToString(), Message = msg, Success = uid > 0 }.ToString();
        }

        public string Edit(bagbidder u)
        {
            int k;
            string msg = "编辑失败。";           
            k = bagbidderDal.Instance.Update(u);
            if (k > 0)
            {
                msg = "编辑成功。";
            }

            return new JsonMessage { Data = k.ToString(), Message = msg, Success = k > 0 }.ToString();
        }

        public string Delete(int Id)
        {
            string msg = "删除失败！";
            int k = 0;

            k = bagbidderDal.Instance.Delete(Id);
            if (k > 0)
            {
                msg = "删除成功。";
            }

            return new JsonMessage { Data = k.ToString(), Message = msg, Success = k > 0 }.ToString();
        }
        public string GetList()
        {
            var devList = bagbidderDal.Instance.GetAll();
            var list = devList as List<bagbidder> ?? devList.ToList();
            return list.Any() ? JSONhelper.ToJson(list) : "[]";
        }
        public string GetJsonData(int pageindex, int pagesize, string filterJson, string sort, string order)
        {
            var pcp = new ProcCustomPage("Vdistender")
            {
                PageIndex = pageindex,
                PageSize = pagesize,
                OrderFields = sort + " " + order,
                WhereString = FilterTranslator.ToSql(filterJson)
            };
            int recordCount;
            DataTable dt = bagbidderDal.Instance.GetPageWithSp(pcp, out recordCount);
            return JSONhelper.FormatJSONForEasyuiDataGrid(recordCount, dt);
        }



    }
}
